﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Controllers
{
    class AssetController : BaseController
    {
        //分页查询
        public ActionResult Find(int start, int limit, string name, DateTime? startDate, DateTime? endDate)
        {
            string sql = @"SELECT No,Sn,a.Name,Class,Model,Spec,Unit,Supplier,Price,BuyDate,Status,KeeperId,b.Name Keeper,DistributeDate,DueTime,Remarks
  FROM Assets a left join Employee b on a.KeeperId=b.Id order by BuyDate desc;";
            IEnumerable<AssetDTO> list = ctx.ExecuteQuery<AssetDTO>(sql);
            if (!string.IsNullOrWhiteSpace(name))
            {
                list = list.Where(r => r.Name.Contains(name));
            }
            if (startDate != null)
            {
                list = list.Where(r => r.BuyDate >= startDate);
            }
            if (endDate != null)
            {
                list = list.Where(r => r.BuyDate <= endDate);
            }
            CJson CJson = new CJson();
            string json = CJson.ToJsonString("totalCount:" + list.Count() + ",data", list.Skip(start).Take(limit).ToList());
            return Content(json);
        }
    }
}